package mutsumimod.cards.deprecated;

import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import mutsumimod.cards.BaseCard;
import mutsumimod.character.Mutsumi;
import mutsumimod.monitors.PathDependencyMonitor;
import mutsumimod.util.CardStats;

import java.util.ArrayList;

@Deprecated
public class PathDependency extends BaseCard  {
    public static final String ID = makeID(PathDependency.class.getSimpleName());
    public static final CardStats info = new CardStats(
            Mutsumi.Meta.CARD_COLOR,
            CardType.SKILL,
            CardRarity.UNCOMMON,
            CardTarget.SELF,
            1
    );

    public PathDependency() {
        super(ID, info);
        setAttr(0,0,1);
        setAttrUpg(0,0,1);
        setShouldCopyUse(true);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }

    @Override
    public void beforeCopy(){
        clearCopyCardsAddSelf();
        addCopyCards(getTopUsedCards());
    }

    public ArrayList<AbstractCard> getTopUsedCards() {
        ArrayList<AbstractCard> res = new ArrayList<>();
        ArrayList<AbstractCard> copyUsedCombat = PathDependencyMonitor.cardsUsedCombat;
        int k = copyUsedCombat.size() - 1;

        while (k >= 0 && res.size() < magicNumber) {
            AbstractCard card = copyUsedCombat.get(k);
            if (!(card instanceof PathDependency)&&!card.type.equals(AbstractCard.CardType.STATUS)&&!card.type.equals(AbstractCard.CardType.CURSE)) {
                res.add(card);
            }
            k--;
        }
        return res;
    }

    @Override
    public PathDependency makeStatEquivalentCopy() {
        PathDependency pathDependency =(PathDependency)super.makeStatEquivalentCopy();
        pathDependency.updateDescription();
        return pathDependency;
    }

    @Override
    public AbstractCard makeCopy() { //Optional
        return new PathDependency();
    }

    @Override
    public void updateDescription() {
        if(AbstractDungeon.player==null){
            rawDescription = cardStrings.DESCRIPTION;
            initializeDescription();
            return;
        }

        if(getInCopyUse()){
            rawDescription = cardStrings.EXTENDED_DESCRIPTION[0];
        }else{
            ArrayList<AbstractCard> topCards=getTopUsedCards();
            if(topCards.isEmpty()){
                rawDescription = cardStrings.DESCRIPTION;
            }else{
                rawDescription = cardStrings.DESCRIPTION+cardStrings.EXTENDED_DESCRIPTION[1];
                for(int i=0;i<topCards.size();i++){
                    rawDescription+="*"+topCards.get(i).name+"， ";
                }
                if (rawDescription.endsWith("， ")) {
                    rawDescription = rawDescription.substring(0, rawDescription.length() - 2);
                }
                rawDescription+=cardStrings.EXTENDED_DESCRIPTION[2];
            }
        }
        initializeDescription();
    }

}